﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Work06._03
{
    class Bank
    {
        static float money = 100.1f;


        static void Main(string[] args)
        {
            choose();
        }

        private static void choose()
        {
            Console.WriteLine("1、存款，2、取款");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1:
                    intMoney();
                    choose();
                    break;
                case 2:
                    outMoney();
                    choose();
                    break;
                default:
                    Console.WriteLine("请正确选择！");
                    break;
            }
        }

        private static void intMoney()
        {
            Console.WriteLine("想要存放在银行账户中的余额:");
            float num1 = float.Parse(Console.ReadLine());
            money = money + num1;
            Console.WriteLine("余额：" + money);
        }

        private static void outMoney()
        {
            try
            {
                Console.WriteLine("想要从银行账户中提取的金额:");
                float num2 = float.Parse(Console.ReadLine());
                if (money < num2)
                {
                    Console.WriteLine("取款金额大于余额，请重新输入");
                    throw new ArgumentOutOfRangeException("名字不合法！");
                }
                money = money - num2;
                Console.WriteLine("余额：" + money);
            }

            catch (ArgumentOutOfRangeException)
            {
                Console.WriteLine("");

            }
            catch (Exception)
            {
                Console.WriteLine("数据类型转换的异常");
            }


        }
    }
}

